bhwi-cli: command to enumerate devices#18
Conversation
…port On Guix System, using guix shell, the C_INCLUDE_PATH remains set but is missing the 32 bit headers. Unsetting it somehow allows cargo/cc to resolve things.
| // generate this trait by putting it over HWI's definition and then also | ||
| // generate the blanket impl which will map the errors to HWIDeviceError | ||
| #[async_trait(?Send)] | ||
| pub trait HWIDevice { |
There was a problem hiding this comment.
Trying to come up with a better solution to this before attempting to write a proc macro. Duplicating all the methods isn't so awful, but not very nice IMO
|
while compiling: and after fixing, I tried running the list without any device. |
|
@edouardparis Thanks for trying it and reviewing! I got a bit lost in trying to create fancy futures stuff, that's why it crashes when it can't find a coldcard emulator.
This is probably a rust version issue? It compiles for me on nightly. Perhaps I should start developing with stable. Anyway, I resolved these issues so you can try again! bfbfe39 I think the flow of unlocking and setting the fingerprint is a little rough right now. Not sure on the best way to design that yet. |
|
Some trait do not need to have more rigid requirement to work with you implementation. I have bhwi-cli compiling with this diff: git diff
diff --git a/bhwi-async/src/lib.rs b/bhwi-async/src/lib.rs
index 082762f..b5e33d2 100644
--- a/bhwi-async/src/lib.rs
+++ b/bhwi-async/src/lib.rs
@@ -20,19 +20,19 @@ pub use ledger::Ledger;
#[async_trait(?Send)]
pub trait Transport {
- type Error: StdError + Send + Sync + Debug + 'static;
+ type Error;
async fn exchange(&mut self, command: &[u8], encrypted: bool) -> Result<Vec<u8>, Self::Error>;
}
#[async_trait(?Send)]
pub trait HttpClient {
- type Error: StdError + Send + Sync + Debug + 'static;
+ type Error;
async fn request(&self, url: &str, request: &[u8]) -> Result<Vec<u8>, Self::Error>;
}
#[async_trait(?Send)]
pub trait HWI {
- type Error: StdError + Send + Sync + Debug + 'static;
+ type Error;
async fn unlock(&mut self, network: Network) -> Result<(), Self::Error>;
async fn get_master_fingerprint(&mut self) -> Result<Fingerprint, Self::Error>;
async fn get_extended_pubkey(
@@ -77,11 +77,7 @@ impl HWIDeviceError {
}
#[derive(Debug, thiserror::Error)]
-pub enum Error<E, F>
-where
- E: StdError + Send + Sync + 'static,
- F: StdError + Send + Sync + 'static,
-{
+pub enum Error<E, F> {
#[error("transport error: {0}")]
Transport(E),
@@ -202,8 +198,8 @@ pub trait OnUnlock {
}
pub trait CommonInterface<C, T, R, E> {
- type TransportError: StdError + Send + Sync + Debug + 'static;
- type HttpClientError: StdError + Send + Sync + Debug + 'static;
+ type TransportError;
+ type HttpClientError;
#[allow(clippy::type_complexity)]
fn components(
@@ -220,8 +216,6 @@ async fn run_command<D, C, E, F>(
command: C,
) -> Result<common::Response, Error<E, F>>
where
- E: StdError + Send + Sync + std::fmt::Debug + 'static,
- F: StdError + Send + Sync + std::fmt::Debug + 'static,
D: CommonInterface<
common::Command,
common::Transmit,For the implementation of HWIDevice we will see later how it goes, If you look at bhwi-wasm I directly used enum instead of trying to keep a special trait. Maybe this enum can be removed later in favor of the HWIDevice trait. |
The main goal of this change is to add a command to bhwi-cli that enumerates all supported devices and displays information (ex. fingerprint) about them so that the user can interact with a device. Lots of tangential changes have also been made as I was trying to build out a decent foundation for adding device enumeration. Large refactors were done in order to make it possible to have heterogeneous vectors of devices. It's not a major benefit but it makes the cli code nicer. This includes the creation of the HWIDevice trait and making error types use thiserror to implement std::error::Error. This also required the bhwi-wasm errors to be changed from JsValue to a wrapper error, WasmError, which converts the errors to strings. Not ideal, but could not find a better solution right now. Lots of the Transports from the e2e crates were moved around and changed for re-usability between the cli crate e2e tests. The rest of the changes were simply writing the Transports (HID and serial backends) used for the currently supported devices.
This is true. Fixed. |
The main goal of this change is to add a command to bhwi-cli that enumerates all
supported devices and displays information (ex. fingerprint) about them so that
the user can interact with a device.
Lots of tangential changes have also been made as I was trying to build out a
decent foundation for adding device enumeration.
Large refactors were done in order to make it possible to have heterogeneous
vectors of devices. It's not a major benefit but it makes the cli code nicer.
This includes the creation of the HWIDevice trait and making error types use
thiserror to implement std::error::Error. This also required the bhwi-wasm
errors to be changed from JsValue to a wrapper error, WasmError, which converts
the errors to strings. Not ideal, but could not find a better solution right
now.
Lots of the Transports from the e2e crates were moved around and changed for
re-usability between the cli crate e2e tests.
The rest of the changes were simply writing the Transports (HID and serial
backends) used for the currently supported devices.